home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / the_independent.swf / scripts / frame_5 / DoAction_3.as < prev    next >
Text File  |  2011-08-19  |  7KB  |  272 lines

  1. function populate()
  2. {
  3.    var p = _root.attachMovie("paperBoy","paperBoy",4500);
  4.    p._y = 760;
  5.    p._x = 150;
  6.    p.onenterframe = movePeople;
  7.    var p = _root.attachMovie("van","van",4501);
  8.    p._y = 760;
  9.    p._x = 0;
  10.    p.onenterframe = movePeople;
  11.    var i = 0;
  12.    while(i <= 5)
  13.    {
  14.       var p = _root.attachMovie("pigeon","pigeon" + i,4900 + i);
  15.       p._x = p.relX = math.random() * 1500;
  16.       p._y = p.relY = 350 - i * 50;
  17.       p.xAcc = math.random() * 3 + 3;
  18.       p.yAcc = 0;
  19.       p._xscale = -100;
  20.       p.num = i;
  21.       p["class"] = "pigeon";
  22.       p.onenterframe = float;
  23.       i++;
  24.    }
  25.    aGroundPos = new array();
  26.    cityLength = 2000;
  27.    cityPos = 0;
  28.    oPeople.num = 10;
  29.    oBackBuild.num = 2;
  30.    oForeBuild.num = 2;
  31.    oObstacles.num = 10;
  32.    oPeople.para = 1;
  33.    oBackBuild.para = 0.5;
  34.    oForeBuild.para = 0.75;
  35.    oObstacles.para = 1;
  36.    oPeople.aPos = [];
  37.    oBackBuild.aPos = [];
  38.    oForeBuild.aPos = [];
  39.    oObstacles.aPos = [];
  40.    oPeople.aType = [];
  41.    oObstacles.aType = [];
  42.    oForeBuild.aType = [];
  43.    oBackBuild.aType = [];
  44.    createPosArray(oPeople);
  45.    createPosArray(oObstacles);
  46.    createPosArray(oForeBuild);
  47.    createPosArray(oBackBuild);
  48.    var f = _root.attachMovie("duffer","duffer",5500);
  49.    f._x = checkPos();
  50.    f._y = _global.movieHeight + 360;
  51.    f["class"] = oBaddy;
  52.    f.onenterframe = movePeople;
  53.    var f = _root.attachMovie("scum","scum",5501);
  54.    f._x = checkPos();
  55.    f._y = _global.movieHeight + 360;
  56.    f["class"] = oBaddy;
  57.    f.onenterframe = movePeople;
  58.    var f = _root.attachMovie("blankMC","floater",100000);
  59.    f._x = f.relX = 0;
  60.    f._y = f.relY = 500;
  61.    f.xAcc = 5;
  62.    f.yAcc = 0;
  63.    f.onenterframe = float;
  64.    var c = _root.attachMovie("blankMC","controller",100001);
  65.    c._x = 250;
  66.    c.targ = floater;
  67.    c.onenterframe = control;
  68.    delete c;
  69. }
  70. function checkPos()
  71. {
  72.    var curX = math.round(math.random() * (cityLength - 400) + 300);
  73.    aGroundPos.push(curX);
  74.    var breaker = 0;
  75.    var k = 0;
  76.    while(k <= aGroundPos.length - 2)
  77.    {
  78.       if(curX > aGroundPos[k] - 40 && curX < aGroundPos[k] + 40)
  79.       {
  80.          curX = math.round(math.random() * (cityLength - 800) + 400);
  81.          aGroundPos[aGroundPos.length - 1] = curX;
  82.          k = -1;
  83.          breaker++;
  84.       }
  85.       if(breaker > 100)
  86.       {
  87.          trace("broken");
  88.          break;
  89.       }
  90.       k++;
  91.    }
  92.    return curX;
  93. }
  94. function removeBuildings(targ)
  95. {
  96.    var i = 0;
  97.    while(i <= _root["o" + targ].aPos.length - 2)
  98.    {
  99.       _root[targ + i].removeMovieClip();
  100.       i++;
  101.    }
  102. }
  103. function createPosArray(oName)
  104. {
  105.    if(oName.num != 10)
  106.    {
  107.       var i = 0;
  108.       while(i < math.round((cityLength + 1000) * oName.para / (_global.movieWidth / oName.num)))
  109.       {
  110.          oName.aPos.push(math.round(math.random() * _global.movieWidth / oName.num + i * (_global.movieWidth / oName.num)));
  111.          oName.aType.push(math.ceil(math.random() * oName.typeNum));
  112.          trace(oName.aPos.length);
  113.          i++;
  114.       }
  115.       oName.aPos.push(undefined);
  116.       var j = 0;
  117.       while(oName.aPos[j] < _global.movieWidth + 150)
  118.       {
  119.          var s = _root.attachMovie(oName.title,oName.title + j,oName.lev + j);
  120.          s._y = oName.yDepth + _global.movieHeight;
  121.          s._x = oName.aPos[j];
  122.          s.gotoandstop(oName.aType[j]);
  123.          s.num = j;
  124.          j++;
  125.          s.Class = oName;
  126.          s.Class.curY = s._y;
  127.          s.onenterframe = move;
  128.       }
  129.       oName.nextBuild = j;
  130.       oName.prevBuild = -1;
  131.    }
  132.    else
  133.    {
  134.       var i = 0;
  135.       while(i <= 9)
  136.       {
  137.          oName.aPos.push(math.round(math.random() * (cityLength - 400) + 300));
  138.          aGroundPos.push(oName.aPos[i]);
  139.          if(aGroundPos.length > 1)
  140.          {
  141.             var breaker = 0;
  142.             var k = 0;
  143.             while(k <= aGroundPos.length - 2)
  144.             {
  145.                if(oName.aPos[i] > aGroundPos[k] - 40 && oName.aPos[i] < aGroundPos[k] + 40)
  146.                {
  147.                   oName.aPos[i] = math.round(math.random() * (cityLength - 800) + 400);
  148.                   aGroundPos[aGroundPos.length - 1] = oName.aPos[i];
  149.                   k = -1;
  150.                   breaker++;
  151.                }
  152.                if(breaker > 100)
  153.                {
  154.                   trace("broken");
  155.                   break;
  156.                }
  157.                k++;
  158.             }
  159.          }
  160.          oName.aType.push(math.ceil(math.random() * oName.typeNum));
  161.          i++;
  162.       }
  163.       var j = 0;
  164.       while(j <= 9)
  165.       {
  166.          var s = _root.attachMovie(oName.title,oName.title + j,oName.lev + j);
  167.          s._y = oName.yDepth + _global.movieHeight;
  168.          s._x = oName.aPos[j];
  169.          s.gotoandstop(oName.aType[j]);
  170.          s.num = j;
  171.          s.Class = oName;
  172.          s.onenterframe = movepeople;
  173.          j++;
  174.       }
  175.    }
  176. }
  177. function slideInPrep(targ, pos)
  178. {
  179.    if(pos == "centre")
  180.    {
  181.       targ._y = math.round((_global.movieHeight - targ._height) / 2);
  182.    }
  183.    else if(pos == "top")
  184.    {
  185.       targ._y = 0;
  186.    }
  187.    targ.endX = math.round((_global.movieWidth - targ._width) / 2);
  188.    trace(targ._width);
  189.    targ.easeIn = 10;
  190.    targ.easeMulti = 4;
  191.    targ.acc = targ.easeIn * targ.easeMulti;
  192.    var i = targ.easeIn;
  193.    while(i >= 1)
  194.    {
  195.       targ.endX += i;
  196.       i--;
  197.    }
  198.    targ._x = math.round((_global.movieWidth - targ.endX) / targ.acc) * targ.acc + targ.endX;
  199.    targ.onenterframe = slideIn;
  200. }
  201. function slideIn()
  202. {
  203.    this._x -= this.acc;
  204.    if(this._x == this.endX)
  205.    {
  206.       this.acc = this.easeIn;
  207.    }
  208.    else if(this._x < this.endX)
  209.    {
  210.       this.acc--;
  211.    }
  212.    if(this.acc == 0)
  213.    {
  214.       delete this.onenterframe;
  215.    }
  216. }
  217. function slideOutPrep(targ)
  218. {
  219.    targ.acc = 0;
  220.    targ.onenterframe = slideOut;
  221. }
  222. function slideOut()
  223. {
  224.    this._x -= this.acc;
  225.    this.acc += 10;
  226.    if(this._x < - this._width)
  227.    {
  228.       this.removeMovieClip();
  229.    }
  230. }
  231. function soundPrep()
  232. {
  233.    createEmptyMovieClip("musicControl",750);
  234.    createEmptyMovieClip("fxControl",751);
  235.    curSound = new Sound(fxControl);
  236.    bgSound = new Sound(musicControl);
  237.    bgSound.attachSound("indyMusic");
  238.    bgSound.setVolume(85);
  239.    var b = _root.attachMovie("soundButton","soundButton",19001);
  240.    b._x = 5;
  241.    b._y = 365;
  242.    b.soundIcon.stop();
  243.    _global.soundOn = true;
  244. }
  245. function playFX(cur)
  246. {
  247.    if(_global.sound)
  248.    {
  249.       curSound.attachSound(cur);
  250.       curSound.start();
  251.    }
  252. }
  253. function soundState(n)
  254. {
  255.    if(n == 2)
  256.    {
  257.       if(_global.section == 1)
  258.       {
  259.          bgSound.setVolume(0);
  260.       }
  261.       _global.sound = false;
  262.    }
  263.    else
  264.    {
  265.       if(_global.section == 1)
  266.       {
  267.          bgSound.setVolume(85);
  268.       }
  269.       _global.sound = true;
  270.    }
  271. }
  272.